<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: LoginRequired.php 394 2010-12-25 13:23:21Z steen.rabol $
 *
 */

class LoginRequired extends PortalSystemPage
{
	public function validateUser($sender,$param)
	{
		$authManager	= $this->Application->getModule('auth');
		if(!$authManager->login($this->Username->Text,$this->Password->Text))
		{
			$param->IsValid	= false;
		}
	}

	public function loginButtonClicked($sender,$param)
	{
		if($this->Page->IsValid)
		{
			// Set the login expire cookie
			$cvalue = time() + ($this->Application->Parameters['LoginExpire'] * 60);
			$cookie = new THttpCookie($this->Application->Parameters['CookiePrefix'] . "_loginexpire",$cvalue);
			$cookie->Expire	= $cvalue;
			$this->Response->Cookies[] = $cookie;
			$authManager	= $this->Application->getModule('auth');
			$this->Response->redirect($authManager->getReturnUrl());
		}
	}

	public function checkUsername($sender,$param)
	{
		$username	= $this->Username->Text;
		$id			= $this->DataAccess->createCommand("select * from tblusers where name='$username'")->queryRow();

		if($id)
		{
			$param->IsValid = true;
		}
		else
		{
			$param->IsValid = false;
		}
	}
}
?>